{extend name="v1/layout/base"}
{block name="content"}
<div class="layuimini-main">
  <script type="text/html" id="toolbar">
    <div class="layui-btn-container">
      <button class="layui-btn layui-btn-black  layui-btn-sm" lay-event="reseve"><i class="layui-icon">&#xe63d;</i></button>
      <button class="layui-btn layui-btn-normal  layui-btn-sm" lay-event="add" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/System/refundReasonCreate"><i class="layui-icon">&#xe654;</i>添加售后原因</button>
    </div>
  </script>

  <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

  <script type="text/html" id="currentTableBar">
    <button class="layui-btn layui-btn-radius layui-btn-warm layui-btn-sm" lay-event="show" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/System/refundReasonEdit"><i class="layui-icon">&#xe642;</i>修改</button>
    <button class="layui-btn layui-btn-radius layui-btn-danger layui-btn-sm" lay-event="delete" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/System/refundReasonDestroy"><i class="layui-icon">&#xe640;</i>删除</button>
  </script>
</div>
{/block}
{block name="myScript"}
<script>
  layui.use(['form', 'table', 'laydate'], function() {
    var $ = layui.jquery,
      form = layui.form,
      laydate = layui.laydate,
      table = layui.table;
    table.render({
      elem: '#currentTableId',
      url: '/{:config("manage.manage_name")}/{:config("manage.version")}/System/refundReason',
      toolbar: '#toolbar',
      defaultToolbar: ['filter'],
      cols: [
        [{
            field: 'refund_reason_id',
            width: '10%',
            title: 'ID',
            sort: true
          },
          {
            field: 'content',
            width: '30%',
            title: '原因',
            edit: 'text',
          },
          {
            field: 'update_time',
            width: '20%',
            title: '更新时间'
          },
          {
            title: '操作',
            toolbar: '#currentTableBar',
            minWidth: '150',
            fixed: 'right',
            align: "center"
          }
        ]
      ],
      limits: [30, 150, 200, 250, 500, 1000],
      limit: 30,
      id: 'table_ids',
      page: false,
      skin: 'line'
    });
    // 监听单元格编辑事件
    table.on('edit(currentTableFilter)', function(obj) {
      var value = obj.value,
        by_key = obj.data.refund_reason_id,
        keywords = $("#keywords").val(),
        key = obj.field;
      if (value == '') {
        return false;
      }
      var url = "{:url('/'.config('manage.manage_name').'/'.config('manage.version').'/System/refundReasonChanageValue')}";
      https(url, {
        by_key: by_key,
        key: key,
        value: value
      }, 'post', true, '正在修改').then(res => {
        if (res.result_code == 200) {
          table.reload('table_ids', {
            where: {
              keywords: keywords
            }
          });
        }
      })
    });
    // 顶部操作工具
    table.on('toolbar(currentTableFilter)', function(obj) {
      var url = $(this).attr('data-url'),
        keywords = $("#keywords").val();
      switch (obj.event) {
        case 'reseve':
          table.reload('table_ids');
          break;
        case 'add':
          var index = layer.open({
            title: '售后原因添加',
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ['100%', '100%'],
            content: url,
            cancel: function() {
              table.reload('table_ids', {
                where: {
                  keywords: keywords
                }
              });
            }
          });
          break;
        case 'search':
          $("#xk-search-status").removeClass('xk-search-status');
          break;
      }
    })
    // 列表工具栏目
    table.on('tool(currentTableFilter)', function(obj) {
      var data = obj.data,
        event = obj.event,
        keywords = $("#keywords").val(),
        url = $(this).attr('data-url');
      url = url + '/refund_reason_id/' + data.refund_reason_id;
      switch (event) {
        case 'show':
          var index = layer.open({
            title: '售后原因编辑',
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ['100%', '100%'],
            content: url,
            cancel: function() {
              table.reload('table_ids', {
                where: {
                  keywords: keywords
                }
              });
            }
          });
          break;
        case 'delete':
          //确定要删除吗？
          layer.msg('您确定要删除这个售后原因吗？', {
            time: 0, //不自动关闭
            btn: ['确定', '取消'],
            yes: function(index) {
              layer.close(index);
              https(url, {
                id_str: data.refund_reason_id,
                status: 3
              }, 'post', true, '正在执行删除').then(res => {
                if (res.result_code == 200) {
                  table.reload('table_ids', {
                    where: {
                      keywords: keywords
                    }
                  });
                }
              })
            },
            btn2: function(index) {
              layer.close(index);
            }
          });
          break;
      }
    })

  });
</script>
{/block}
